python numbers模块 python *numbers | 您所在的位置:网站首页 › numbers 格式刷 › python numbers模块 python *numbers |
python numbers模块 python *numbers
转载
imking 2023-07-01 11:23:26 文章标签 python numbers模块 python number Python 随机数 文章分类 Python 后端开发 Numberstypeint (10,100) long (5167466L) float (12.5) complex (12.8-3.14j) a = 10 b = 12.5 c = 5147638L d = 5.1 - 3.14j print type(a) print type(b) print type(c) print type(d)结果: Number TypeConversion· int(x) to convert x to aplain integer. · long(x) to convert x toa long integer. · float(x) to convert x toa floating-point number. · complex(x)/ complex(x, y) toconvert x to a complex number with real part x and imaginary part zero. Mathematical FunctionsFunction Returns ( description ) abs(x) The absolute value of x: the (positive) distance between x and zero. ceil(x) The ceiling of x: the smallest integer not less than x cmp(x, y) -1 if x < y, 0 if x == y, or 1 if x > y exp(x) The exponential of x: ex fabs(x) The absolute value of x. floor(x) The floor of x: the largest integer not greater than x log(x) The natural logarithm of x, for x> 0 log10(x) The base-10 logarithm of x for x> 0 . max(x1, x2,...) The largest of its arguments: the value closest to positive infinity min(x1, x2,...) The smallest of its arguments: the value closest to negative infinity modf(x) The fractional and integer parts of x in a two-item tuple. Both parts have the same sign as x. The integer part is returned as a float. pow(x, y) The value of x**y. round(x [,n]) x rounded to n digits from the decimal point. Python rounds away from zero as a tie-breaker: round(0.5) is 1.0 and round(-0.5) is -1.0. sqrt(x) The square root of x for x > 0 Random Number Functions随机数字用于游戏,模拟,测试,安全和隐私应用。 Python包含以下常用功能。 Function Description choice(seq) A random item from a list, tuple, or string. randrange ([start,] stop [,step]) A randomly selected element from range(start, stop, step) random() A random float r, such that 0 is less than or equal to r and r is less than 1 seed([x]) Sets the integer starting value used in generating random numbers. Call this function before calling any other random module function. Returns None. shuffle(lst) Randomizes the items of a list in place. Returns None. uniform(x, y) A random float r, such that x is less than or equal to r and r is less than y
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。 赞 收藏 评论 分享 举报 上一篇:python 一行 python一行输入两个整数 下一篇:python method大小写 python中的大小写转换 |
CopyRight 2018-2019 实验室设备网 版权所有 |